<?php
include('inc_head.php');
$id=$wu->request_int('id');
$tag=$wu->request_string('tag');
if(!$tag) 		die('参数有误');
$data=array('Name'=>'','Ordinal'=>'999','ParentID'=>$wu->request_int('pid'));
if($id){
	$data=$db->fetch_row("select * from tgeneralcatalog where ID=$id");
	if(!$data) die('记录不存在');
}
if($wu->request_string("act")=='save'){
	if($id){
		$db->update('tgeneralcatalog',"Name='".$wu->request_string('Name')."', ParentID=".$wu->request_int('ParentID').", Ordinal=".$wu->request_int('Ordinal'),"ID=".$id);
		$wu->redirect('编辑成功',"?tag=$tag&id=".$id);
	}else{
		$db->insert('tgeneralcatalog','Name,ParentID,Ordinal,ExTags',"'".$wu->request_string('Name')."',".$wu->request_int('ParentID').", ".$wu->request_int('Ordinal').", '$tag'");
		$wu->redirect('新增成功','catalog_list.php?tag='.$tag);
	}
}
	
?>
<form action="#" method="post" >
<h1>编辑分类<a href="catalog_list.php?tag=<?php echo $tag; ?>">[列表管理]</a></h1>
<table cellpadding="0" cellspacing="0">名称</td><td><input type="text" name="Name" value="<?php echo $data['Name']; ?>" /><span class="help-block">长度不超过15个汉字.</span></td></tr>
    <tr><td>父级</td><td><select name="ParentID"><?php echo $biz->get_generaltree($data['ParentID'],'tgeneralcatalog',$tag); ?></select></td></tr>
    <tr><td>顺序</td><td><input type="text" name="Ordinal" value="<?php echo $data['Ordinal']; ?>" /></td></tr>
    <tr><td>
            <input type="submit" value="保存" />
            <input type="reset" class="btn" value="重置" />
            <input type="hidden" name="act" value="save" />
        </td></tr>
</fieldset>
</form>
<?php
	include('inc_foot.php');
?>